package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckgroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author zhangmeng
 * @description 检查项Controller
 * @date 2019/9/16
 **/
@RestController
@RequestMapping("/checkgroup")
@Slf4j
public class CheckgroupController {

    @Resource
    private CheckgroupService checkgroupService;

    /**
     * 新增
     * 1、rpc调用完成新增业务
     * 2、返回结果
     * @param checkGroup
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody CheckGroup checkGroup){
        log.info("[检查组-新增]data:{}",checkGroup);
        checkgroupService.add(checkGroup);
        return new Result(true,MessageConst.ADD_CHECKGROUP_SUCCESS);
    }

    /**
     * 分页查询
     *
     * @param queryPageBean
     * @return
     */
    @GetMapping("findPage")
    public Result findPage(QueryPageBean queryPageBean) {
        log.info("[检组项-分页查询]data:{}", queryPageBean);
        //rpc查询数据
        PageResult pageResult = checkgroupService.pageQuery(queryPageBean);
        //封装返回结果
        return new Result(true,MessageConst.ACTION_SUCCESS, pageResult);
    }

    /**
     * 根据id删除
     *
     * @param id
     * @return
     */
    @RequestMapping("/deleteCheckGroupitemById")
    public Result delete(Integer id){
        log.info("[检查组-根据id删除]id：{}",id);
        //RPC调用处理业务
        checkgroupService.delete(id);
        return new Result(true,MessageConst.DELETE_CHECKGROUP_SUCCESS);
    }

    /**
     * 编辑
     *
     * @param checkGroup
     * @return
     */
    @PostMapping("/edit")
    public Result edit(@RequestBody CheckGroup checkGroup) {
        log.info("[检查组-编辑]data:{}", checkGroup);
        checkgroupService.edit(checkGroup);
        return new Result(true, MessageConst.EDIT_CHECKGROUP_SUCCESS);
    }

    /**
     * 根据Id查询
     *
     * @param id
     * @return
     */
    @RequestMapping("/findById")
    public Result findById(Integer id) {
        log.info("[检查组-根据ID查询]id:{}", id);
        CheckGroup checkGroup = checkgroupService.findById(id);
        return new Result(true,MessageConst.ACTION_SUCCESS,checkGroup);
    }
}
